home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 December / Disc 1 / APCCD01200.ISO / workshop / c / files / log3.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-01  |  719 b   |  45 lines

  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5.  
  6. void TooLowMsg()
  7. {
  8.    cout << endl
  9.         << "Value must be bigger than 0"
  10.         << endl;
  11. }
  12. double GetValue()
  13. {
  14.    double val;
  15.    do {
  16.       cout << "Enter the value: "
  17.            << flush;
  18.       cin >> val;
  19.       if (val<=0.0)
  20.          TooLowMsg();
  21.    } while (val<=0.0);
  22.    return val;
  23. }
  24.  
  25. int main(int argc, char *argv[])
  26. {
  27.    int retval = 0;
  28.    double val = -1.0;
  29.  
  30.    if (argc>1) {
  31.       val = atof(argv[1]);
  32.       if (val<=0.0)
  33.          TooLowMsg();
  34.    }
  35.    if (val<=0.0)
  36.       val = GetValue();
  37.  
  38.    cout << "The log of "
  39.         << val 
  40.         << " is "
  41.         << log(val)
  42.         << endl;
  43.  
  44.    return 0;
  45. }